const path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");

const webpackDevServer = require('webpack-dev-server');
const config = require("./webpack.config.js");

module.exports = {
    entry: ['./src/index.js'],
    output: {
        path: path.join(__dirname, "public"),
        filename: 'index.js',
        publicPath: "/"
    },
    module: {
        rules: [
            {
                test: /\.html$/,
                use: ['raw-loader'] // loaders: ['raw-loader'] is also perfectly acceptable.
            }, {
                test: /\.js$/,
                enforce: "post",
                use: ['es3ify-loader']
            }, {
                test: /\.css$/,
                use: ExtractTextPlugin.extract({fallback: "style-loader", use: "css-loader"})
            }, {
                test: /\.less$/,
                use: ExtractTextPlugin.extract({
                    fallback: "style-loader",
                    use: ['css-loader', 'less-loader']
                })
            }
        ]
    },
    plugins: [
        new webpack.BannerPlugin('这个插件用来写几个字'),
        // ExtractTextPlugin，抽取CSS代码
        new ExtractTextPlugin("index.css"),
        // CommonsChunkPlugin，抽取JS公共代码
        new webpack.optimize.CommonsChunkPlugin({name: "commons", filename: "commons.js"}),
        // UglifyJsPlugin，压缩JS代码
        new webpack.optimize.UglifyJsPlugin(),
        new HtmlWebpackPlugin({template: './src/index.html'}),
        new webpack.HotModuleReplacementPlugin()
    ],
    devServer: {
        contentBase: path.join(__dirname, "src"),
        compress: true,
        port: 9999
    }
}
